package com.rizzo.infrastructure.redis.serializer;

import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

/**
 * Created by IntelliJ IDEA.
 * User: jalie
 * Date: 11/14/12
 * Time: 6:39 PM
 * To change this template use File | Settings | File Templates.
 */
public class LongSerializer implements RedisSerializer<Long> {

    @Override
    public byte[] serialize(Long aLong) throws SerializationException {
        if (aLong != null) {
            return aLong.toString().getBytes();
        } else {
            return null;
        }
    }

    @Override
    public Long deserialize(byte[] bytes) throws SerializationException {
        if (bytes != null) {
            return Long.valueOf(new String(bytes));
        } else {
            return null;
        }
    }

}
